﻿using System.Web;
using System.Web.Mvc;

namespace NMA.Web.Core.Extensions
{
    public static class StaticContentHelper
    {
        public static string ImageUrl(this HtmlHelper helper, string imageFile)
        {
            return VirtualPathUtility.ToAbsolute("~/Content/images/" + imageFile);
        }

        public static string RegisterCss(string cssFile)
        {
            var scriptPath = VirtualPathUtility.ToAbsolute("~/Content/css/" + cssFile);
            return string.Format("<link href=\"{0}\" rel=\"stylesheet\" type=\"text/css\" >", scriptPath);
        }

        public static string RegisterCssWithAbsolutePath(string cssPath, string fileName)
        {
            string path;
            if (cssPath.StartsWith("~"))
            {
                path = cssPath;
            }
            else
            {
                path = "~" + cssPath;
            }
            cssPath = VirtualPathUtility.ToAbsolute(path) + "/" + fileName;
            return string.Format("<link href=\"{0}\" rel=\"stylesheet\" type=\"text/css\" >", cssPath);
        }

        public static string RegisterScript(string scriptFileName)
        {
            string scriptRoot = VirtualPathUtility.ToAbsolute("~/Scripts");
            string scriptFormat = "<script src=\"{0}/{1}\" type=\"text/javascript\" ></script>";
            return string.Format(scriptFormat, scriptRoot, scriptFileName);
        }        
    }
}